package org.cfx.org.service.impl;

import org.cfx.org.domain.Department;
import org.cfx.org.domain.Employee;
import org.cfx.org.mapper.EmployeeMapper;
import org.cfx.org.query.EmployeeQuery;
import org.cfx.org.service.IEmployeeService;
import org.cfx.org.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void add(Employee employee) {
        employeeMapper.add(employee);
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    public void delete(Long id) {
        employeeMapper.delete(id);
    }

    @Override
    public Employee queryById(Long id) {
        return employeeMapper.queryById(id);
    }

    @Override
    public List<Employee> queryAll() {
        return employeeMapper.queryAll();
    }

    @Override
    public PageInfo<Employee> queryAllPage(EmployeeQuery employeeQuery) {
        Long count = employeeMapper.queryCount(employeeQuery);
        if (count == 0) {
            return new PageInfo<>();
        }else {
            List<Employee> employees = employeeMapper.queryAllPage(employeeQuery);
            return new PageInfo<>(count,employees);
        }
    }

    @Override
    public List<Employee> query() {
        return employeeMapper.query();
    }

    @Override
    public List<Employee> queryManager() {
        return employeeMapper.queryManager();
    }
}
